package com.ziyia.a255;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterViewFlipper;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    int[] imageIds = new int[]{
            R.drawable.bomb7, R.drawable.bomb8, R.drawable.bomb9,
            R.drawable.bomb10, R.drawable.bomb11, R.drawable.bomb12,
            R.drawable.bomb13, R.drawable.bomb14, R.drawable.bomb15,
            R.drawable.bomb16
    };

    private AdapterViewFlipper adapterViewFlipper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        adapterViewFlipper = findViewById(R.id.fliipper);

        BaseAdapter baseAdapter = new BaseAdapter() {
            @Override
            public int getCount() {
                return imageIds.length;
            }

            @Override
            public Object getItem(int position) {
                return imageIds[position];
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView imageView;
                TextView textView = new TextView(MainActivity.this);

                textView.setText("TextView - " + position);

                if (convertView == null) {
                    imageView = new ImageView(MainActivity.this);
                } else {
                    imageView = (ImageView) convertView;
                }
                imageView.setBackgroundResource(imageIds[position]);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                imageView.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                return imageView;
            }
        };
        adapterViewFlipper.setAdapter(baseAdapter);
    }


    public void auto(View view) {
        adapterViewFlipper.startFlipping();
    }

    public void next(View view) {
        adapterViewFlipper.showNext();
        adapterViewFlipper.stopFlipping();
    }

    public void prev(View view) {
        adapterViewFlipper.showPrevious();;
        adapterViewFlipper.stopFlipping();
    }
}